package com.ysu.zyw.fk.handler;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * ViewExceptionHandler is a spring impl to handle all controller level exception(do not contain render part),
 * so we set an exception handler to handle exception and log it, then if an exception raised,
 * return an error page to spring mvc to render.
 * <p>
 * Created by ZeRur on 2016/1/17.
 *
 * @author yaowu.zhang
 */
public class ViewExceptionHandler implements HandlerExceptionResolver {

    private static final Logger logger = LoggerFactory.getLogger(ViewExceptionHandler.class);

    @Override
    public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
        logger.error("ViewExceptionHandler catch an exception " + ex.getMessage(), ex);
        // TODO
        return null;
    }

}
